<?php

namespace Hilaoyu\LaravelExtend\Services\XcfsCient\Controllers;

use Hilaoyu\LaravelExtend\ControllerBase;
use Hilaoyu\LaravelExtend\Services\XcfsCient\XcfsClient;

use Hilaoyu\Utils\UtilSupport;
use Illuminate\Http\Request;


class XcfsController extends ControllerBase
{


    public function __construct()
    {
        UtilSupport::tryQuiet(function () {
            parent::__construct();
        });

    }



    public function apiGenerateUploadToken(Request $request)
    {
        $directory = $request->route("directory",$request->input("directory",""));
        if(!$directory){
            return comResponse()->failed("参数错误")->json();
        }

        $xcfs = new XcfsClient();
        $result = $xcfs->generateToken($directory);
        if(!$result){
            return comResponse()->failed("错误")->withErrors($xcfs->getError())->json();
        }
        return comResponse()->success()->with($result)->json();
    }

    public function ApiSignUrl(Request $request)
    {
        $uri = $request->route("uri",$request->input("uri",""));
        $url = $uri;
        if($uri){
            $url = XcfsClient::SignResponseUrl($uri);
        }

        return comResponse()->success()->with(["url"=>$url])->json();
    }


}
